function getCookie(name) {
    var prefix = name + "="  // name=
    console.log(document.cookie) // name=wangwu; Hm_lvt_eaa57ca47dacb4ad4f5a2570
    // name=  第一次出现的位置
    var start = document.cookie.indexOf(prefix)
    if (start == -1) {
        return null;
    }
    // 从0+5这个位置开始，找到;第一次出现的位置，也就是这个cookie值得结束位置
    var end = document.cookie.indexOf(";", start + prefix.length)
    // name=wangwu
    // Hm_lvt_eaa57ca47dacb4ad4f5a2570;name=wangwu
    // 将字符串得总长度就是截取值得结束位置
    if (end == -1) { // 没有找到分号
        end = document.cookie.length;
    }
    var value = document.cookie.substring(start + prefix.length, end)
    return unescape(value);
}

var userId = getCookie("userid")

var currPage = 1

var pageSize = 5

console.log(typeof pageSize)

var search = location.search

var arr = search.split("=")

if (arr.length > 1) {
    currPage = arr[1]
}

if (currPage > 0 && currPage < 100) {
    page = currPage;
} else {
    page = 1;
}

console.log(page)
console.log(pageSize)
console.log(userId)

$.ajax({
    url: "http://localhost:8080/user/aftersaler",
    data: "currPage=" + page + "&pageSize=" + pageSize + "&userId=" + userId,
    asyne: false,
    dataType: "json",
    type: "get",
    success: function (data) {
        let html = ''
        var list = data.data.list
        for (let i = 0; i < list.length; i++) {
            html += `<div class="details">
                        <img width="184px" height="100px" src="${list[i].goodPhoto}" alt="" class="details_img">
                        <ul class="aftersale_details_ul">
                            <li class="aftersale_details_li">${list[i].orderId}</li>
                            <li class="aftersale_details_li">${list[i].orderState}</li>
                            <li class="aftersale_details_li">${list[i].aftersaleRequi}</li>
                            <li class="aftersale_details_li">${list[i].aftersaleSolve}</li>
                            <li class="aftersale_details_li">${list[i].orderCount}</li>
                            <li class="aftersale_details_li">${list[i].orderMoney}</li>
                            <li class="aftersale_details_li_goodname">${list[i].goodName}</li>
                        </ul>
                    </div>`
        }
        $(".mc_show").append(html)

        generatePage(data.data.navigatepageNums, data.data.pageNum, data.data.pages)
    }
})

function generatePage(navigatepageNums, pageNum, pages) {
    var html = ''
    if (pageNum == 1) {
        html += `<nav class="lf_up"><a href="#" style="cursor: not-allowed">上一页</a></nav>`
    } else {
        html += `<nav class="lf_up"><a href="http://localhost:63343/qiguai/html/uaftsale.html?currPage=${pageNum - 1}">上一页</a></nav>`
    }

    for (let i = 0; i < navigatepageNums.length; i++) {
        if (pageNum == navigatepageNums[i]) {
            html += `<nav class="pagehave"><a href="#" class="pagehave">${navigatepageNums[i]}</a></nav>`
        } else {
            html += `<nav class="pagehave"><a href="http://localhost:63343/qiguai/html/uaftsale.html?currPage=${navigatepageNums[i]}" class="pagenone">${navigatepageNums[i]}</a></nav>`
        }
    }

    if (pageNum == pages) {
        html += `<nav class="lf_dowm"><a href="#" style="cursor: not-allowed">下一页</a></nav>`
    } else {
        html += `<nav class="lf_dowm"><a href="http://localhost:63343/qiguai/html/uaftsale.html?currPage=${pageNum + 1}">下一页</a></nav>`
    }
    $(".pagemain").append(html)
}